package com.mls.fivedistrict.util;

import java.util.*;

/**
 * Created by chenxiuxiang on 2018/3/16.
 */
public class PookerTest {
    public static void main(String[] args) {
        function();
    }

    public static void function() {
        //定义集合 装牌
        HashMap<Integer, String> pooker = new HashMap<Integer, String>();
        //定义集合  存储每张牌的编号
        List<Integer> numbers = new ArrayList<Integer>();
        //定义花色数组
        String[] huase = {"♠", "♥", "♣", "♦"};
        //定义牌号数组，除大王外的2--3
        String[] shuzi = {"2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3"};
        //定义整数变量，作为键
        int index = 2;
        //遍历数组，组合花色和数字，存储在map集合中
        for (String hua : huase) {
            for (String num : shuzi) {
                pooker.put(index, hua + num);
                numbers.add(index);
                index++;
            }
        }
        //打印出所有牌
        //System.out.println(pooker);

        //洗牌，使用Collections类的shuffle方法
        Collections.shuffle(numbers);
        //System.out.println(numbers);
        // 发牌，定义四个集合，三个玩家一个底牌
        ArrayList<Integer> palyer1 = new ArrayList<Integer>();
        ArrayList<Integer> palyer2 = new ArrayList<Integer>();
        ArrayList<Integer> palyer3 = new ArrayList<Integer>();
        ArrayList<Integer> bootom = new ArrayList<Integer>();

        //对numbers遍历
        for (int i = 0; i < numbers.size(); i++) {
            //优先取出三张牌作为底牌
            if (i < 3) {
                bootom.add(numbers.get(i));
            }
            //对索引%3,等于0将牌发给玩家1,1玩家2,2玩家3;
            else if (i % 3 == 0) {
                palyer1.add(numbers.get(i));
            } else if (i % 3 == 1) {
                palyer2.add(numbers.get(i));
            } else if (i % 3 == 2) {
                palyer3.add(numbers.get(i));
            }
        }
        Collections.sort(palyer1);
        Collections.sort(palyer2);
        Collections.sort(palyer3);
        //看牌
        look("玩家一", palyer1, pooker);
        look("玩家二", palyer2, pooker);
        look("玩家三", palyer3, pooker);
        look("底牌", bootom, pooker);

    }

    //定义方法
    public static void look(String name, ArrayList<Integer> player, Map<Integer, String> pooker) {
        //遍历number集合，获得元素作为键，取值
        for (Integer s : player) {
            String value = pooker.get(s);
            System.out.print(value + "");

        }
        System.out.println();
    }
}
